import React, { useEffect } from 'react';
import { Tabs } from '@ant-design/react-native';
import ReleaseJobsTab from './releaseJobTab';
import AreaJobsTab from './areaJobTab';
import MaintainJobTab from './maintainJobTab';
import MaintainJobStore from './maintainJobStore';
import ReleaseJobStore from './releaseJobStore';
import AreaJobStore from './areaJobStore';
import UserStore from '@/stores/userStore';
import dayjs from 'dayjs';

function MaintainHome({ navigation }) {
  const mjStore = MaintainJobStore.useStore();
  const rjStore = ReleaseJobStore.useStore();
  const ajStore = AreaJobStore.useStore();
  const userStore = UserStore.useStore();
  const { filterCond: ajfc } = ajStore;
  const { filterCond: rjfc } = rjStore;
  useEffect(() => {
    handleLoadJob({
      // startDate: dayjs().startOf('day').subtract(1, 'day'),
      startDate: dayjs('1900-01-01'),
      endDate: dayjs().startOf('day'),
    });
  }, []);
  const handleLoadJob = async (filter) => {
    ajStore.getJobList(userStore.user.LoginName, { ...ajfc, ...filter });
    rjStore.getJobList(userStore.user.LoginName, { ...rjfc, ...filter });
    mjStore.getJobList(userStore.user.LoginName);
  };
  return (
    <Tabs
      tabs={[
        {
          title: `放行任务${(rjStore.list || []).length}`,
        },
        {
          title: `区域派工${(ajStore.list || []).length}`,
        },
        {
          title: `维修任务${
            (mjStore.list[0] || []).length +
            (mjStore.list[1] || []).length +
            (mjStore.finishTasks || []).length
          }`,
        },
      ]}
    >
      <ReleaseJobsTab />
      <AreaJobsTab />
      <MaintainJobTab />
    </Tabs>
  );
}

MaintainHome.routeName = 'MaintainHomePage';
MaintainHome.permission = 'RMaintainHome';
export default MaintainHome;
